package o;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ConcurrentModificationException;
import java.util.Map;

public class dy<K, V> {
    static int ˊ;
    static int ˋ;
    @Nullable
    static Object[] ˎ;
    @Nullable
    static Object[] ॱ;
    Object[] ʼ;
    int ʽ;
    int[] ॱॱ;

    private static int ˋ(int[] iArr, int i, int i2) {
        try {
            return dt.ˋ(iArr, i, i2);
        } catch (ArrayIndexOutOfBoundsException e) {
            throw new ConcurrentModificationException();
        }
    }

    int ˎ(Object obj, int i) {
        int i2 = this.ʽ;
        if (i2 == 0) {
            return -1;
        }
        int ˋ = ˋ(this.ॱॱ, i2, i);
        if (ˋ < 0 || obj.equals(this.ʼ[ˋ << 1])) {
            return ˋ;
        }
        int i3 = ˋ + 1;
        while (i3 < i2 && this.ॱॱ[i3] == i) {
            if (obj.equals(this.ʼ[i3 << 1])) {
                return i3;
            }
            i3++;
        }
        ˋ--;
        while (ˋ >= 0 && this.ॱॱ[ˋ] == i) {
            if (obj.equals(this.ʼ[ˋ << 1])) {
                return ˋ;
            }
            ˋ--;
        }
        return i3 ^ -1;
    }

    int ॱ() {
        int i = this.ʽ;
        if (i == 0) {
            return -1;
        }
        int ˋ = ˋ(this.ॱॱ, i, 0);
        if (ˋ < 0 || this.ʼ[ˋ << 1] == null) {
            return ˋ;
        }
        int i2 = ˋ + 1;
        while (i2 < i && this.ॱॱ[i2] == 0) {
            if (this.ʼ[i2 << 1] == null) {
                return i2;
            }
            i2++;
        }
        ˋ--;
        while (ˋ >= 0 && this.ॱॱ[ˋ] == 0) {
            if (this.ʼ[ˋ << 1] == null) {
                return ˋ;
            }
            ˋ--;
        }
        return i2 ^ -1;
    }

    private void ˎ(int i) {
        Object[] objArr;
        if (i == 8) {
            synchronized (dy.class) {
                if (ॱ != null) {
                    objArr = ॱ;
                    this.ʼ = objArr;
                    ॱ = (Object[]) objArr[0];
                    this.ॱॱ = (int[]) objArr[1];
                    objArr[1] = null;
                    objArr[0] = null;
                    ˊ--;
                    return;
                }
            }
        } else if (i == 4) {
            synchronized (dy.class) {
                if (ˎ != null) {
                    objArr = ˎ;
                    this.ʼ = objArr;
                    ˎ = (Object[]) objArr[0];
                    this.ॱॱ = (int[]) objArr[1];
                    objArr[1] = null;
                    objArr[0] = null;
                    ˋ--;
                    return;
                }
            }
        }
        this.ॱॱ = new int[i];
        this.ʼ = new Object[(i << 1)];
    }

    private static void ˊ(int[] iArr, Object[] objArr, int i) {
        int i2;
        if (iArr.length == 8) {
            synchronized (dy.class) {
                if (ˊ < 10) {
                    objArr[0] = ॱ;
                    objArr[1] = iArr;
                    for (i2 = (i << 1) - 1; i2 >= 2; i2--) {
                        objArr[i2] = null;
                    }
                    ॱ = objArr;
                    ˊ++;
                }
            }
        } else if (iArr.length == 4) {
            synchronized (dy.class) {
                if (ˋ < 10) {
                    objArr[0] = ˎ;
                    objArr[1] = iArr;
                    for (i2 = (i << 1) - 1; i2 >= 2; i2--) {
                        objArr[i2] = null;
                    }
                    ˎ = objArr;
                    ˋ++;
                }
            }
        }
    }

    public dy() {
        this.ॱॱ = dt.ॱ;
        this.ʼ = dt.ˋ;
        this.ʽ = 0;
    }

    public dy(int i) {
        if (i == 0) {
            this.ॱॱ = dt.ॱ;
            this.ʼ = dt.ˋ;
        } else {
            ˎ(i);
        }
        this.ʽ = 0;
    }

    public dy(dy<K, V> dyVar) {
        this();
        if (dyVar != null) {
            ˏ((dy) dyVar);
        }
    }

    public void clear() {
        if (this.ʽ > 0) {
            int[] iArr = this.ॱॱ;
            Object[] objArr = this.ʼ;
            int i = this.ʽ;
            this.ॱॱ = dt.ॱ;
            this.ʼ = dt.ˋ;
            this.ʽ = 0;
            ˊ(iArr, objArr, i);
        }
        if (this.ʽ > 0) {
            throw new ConcurrentModificationException();
        }
    }

    public void ˊ(int i) {
        int i2 = this.ʽ;
        if (this.ॱॱ.length < i) {
            Object obj = this.ॱॱ;
            Object obj2 = this.ʼ;
            ˎ(i);
            if (this.ʽ > 0) {
                System.arraycopy(obj, 0, this.ॱॱ, 0, i2);
                System.arraycopy(obj2, 0, this.ʼ, 0, i2 << 1);
            }
            ˊ(obj, obj2, i2);
        }
        if (this.ʽ != i2) {
            throw new ConcurrentModificationException();
        }
    }

    public boolean containsKey(@Nullable Object obj) {
        return ˎ(obj) >= 0;
    }

    public int ˎ(@Nullable Object obj) {
        return obj == null ? ॱ() : ˎ(obj, obj.hashCode());
    }

    int ˏ(Object obj) {
        int i = 1;
        int i2 = this.ʽ * 2;
        Object[] objArr = this.ʼ;
        if (obj == null) {
            while (i < i2) {
                if (objArr[i] == null) {
                    return i >> 1;
                }
                i += 2;
            }
        } else {
            while (i < i2) {
                if (obj.equals(objArr[i])) {
                    return i >> 1;
                }
                i += 2;
            }
        }
        return -1;
    }

    public boolean containsValue(Object obj) {
        return ˏ(obj) >= 0;
    }

    @Nullable
    public V get(Object obj) {
        return getOrDefault(obj, null);
    }

    public V getOrDefault(Object obj, V v) {
        int ˎ = ˎ(obj);
        return ˎ >= 0 ? this.ʼ[(ˎ << 1) + 1] : v;
    }

    public K ॱ(int i) {
        return this.ʼ[i << 1];
    }

    public V ˋ(int i) {
        return this.ʼ[(i << 1) + 1];
    }

    public V ॱ(int i, V v) {
        int i2 = (i << 1) + 1;
        V v2 = this.ʼ[i2];
        this.ʼ[i2] = v;
        return v2;
    }

    public boolean isEmpty() {
        return this.ʽ <= 0;
    }

    @Nullable
    public V put(K k, V v) {
        int ॱ;
        int i;
        int i2 = 8;
        int i3 = this.ʽ;
        if (k == null) {
            ॱ = ॱ();
            i = 0;
        } else {
            i = k.hashCode();
            ॱ = ˎ(k, i);
        }
        if (ॱ >= 0) {
            int i4 = (ॱ << 1) + 1;
            V v2 = this.ʼ[i4];
            this.ʼ[i4] = v;
            return v2;
        }
        ॱ ^= -1;
        if (i3 >= this.ॱॱ.length) {
            if (i3 >= 8) {
                i2 = (i3 >> 1) + i3;
            } else if (i3 < 4) {
                i2 = 4;
            }
            Object obj = this.ॱॱ;
            Object obj2 = this.ʼ;
            ˎ(i2);
            if (i3 != this.ʽ) {
                throw new ConcurrentModificationException();
            }
            if (this.ॱॱ.length > 0) {
                System.arraycopy(obj, 0, this.ॱॱ, 0, obj.length);
                System.arraycopy(obj2, 0, this.ʼ, 0, obj2.length);
            }
            ˊ(obj, obj2, i3);
        }
        if (ॱ < i3) {
            System.arraycopy(this.ॱॱ, ॱ, this.ॱॱ, ॱ + 1, i3 - ॱ);
            System.arraycopy(this.ʼ, ॱ << 1, this.ʼ, (ॱ + 1) << 1, (this.ʽ - ॱ) << 1);
        }
        if (i3 != this.ʽ || ॱ >= this.ॱॱ.length) {
            throw new ConcurrentModificationException();
        }
        this.ॱॱ[ॱ] = i;
        this.ʼ[ॱ << 1] = k;
        this.ʼ[(ॱ << 1) + 1] = v;
        this.ʽ++;
        return null;
    }

    public void ˏ(@NonNull dy<? extends K, ? extends V> dyVar) {
        int i = 0;
        int i2 = dyVar.ʽ;
        ˊ(this.ʽ + i2);
        if (this.ʽ != 0) {
            while (i < i2) {
                put(dyVar.ॱ(i), dyVar.ˋ(i));
                i++;
            }
        } else if (i2 > 0) {
            System.arraycopy(dyVar.ॱॱ, 0, this.ॱॱ, 0, i2);
            System.arraycopy(dyVar.ʼ, 0, this.ʼ, 0, i2 << 1);
            this.ʽ = i2;
        }
    }

    @Nullable
    public V putIfAbsent(K k, V v) {
        V v2 = get(k);
        if (v2 == null) {
            return put(k, v);
        }
        return v2;
    }

    @Nullable
    public V remove(Object obj) {
        int ˎ = ˎ(obj);
        if (ˎ >= 0) {
            return ˏ(ˎ);
        }
        return null;
    }

    public boolean remove(Object obj, Object obj2) {
        int ˎ = ˎ(obj);
        if (ˎ >= 0) {
            Object ˋ = ˋ(ˎ);
            if (obj2 == ˋ || (obj2 != null && obj2.equals(ˋ))) {
                ˏ(ˎ);
                return true;
            }
        }
        return false;
    }

    public V ˏ(int i) {
        int i2 = 8;
        V v = this.ʼ[(i << 1) + 1];
        int i3 = this.ʽ;
        if (i3 <= 1) {
            ˊ(this.ॱॱ, this.ʼ, i3);
            this.ॱॱ = dt.ॱ;
            this.ʼ = dt.ˋ;
            i2 = 0;
        } else {
            int i4 = i3 - 1;
            if (this.ॱॱ.length <= 8 || this.ʽ >= this.ॱॱ.length / 3) {
                if (i < i4) {
                    System.arraycopy(this.ॱॱ, i + 1, this.ॱॱ, i, i4 - i);
                    System.arraycopy(this.ʼ, (i + 1) << 1, this.ʼ, i << 1, (i4 - i) << 1);
                }
                this.ʼ[i4 << 1] = null;
                this.ʼ[(i4 << 1) + 1] = null;
                i2 = i4;
            } else {
                if (i3 > 8) {
                    i2 = (i3 >> 1) + i3;
                }
                Object obj = this.ॱॱ;
                Object obj2 = this.ʼ;
                ˎ(i2);
                if (i3 != this.ʽ) {
                    throw new ConcurrentModificationException();
                }
                if (i > 0) {
                    System.arraycopy(obj, 0, this.ॱॱ, 0, i);
                    System.arraycopy(obj2, 0, this.ʼ, 0, i << 1);
                }
                if (i < i4) {
                    System.arraycopy(obj, i + 1, this.ॱॱ, i, i4 - i);
                    System.arraycopy(obj2, (i + 1) << 1, this.ʼ, i << 1, (i4 - i) << 1);
                }
                i2 = i4;
            }
        }
        if (i3 != this.ʽ) {
            throw new ConcurrentModificationException();
        }
        this.ʽ = i2;
        return v;
    }

    @Nullable
    public V replace(K k, V v) {
        int ˎ = ˎ((Object) k);
        if (ˎ >= 0) {
            return ॱ(ˎ, v);
        }
        return null;
    }

    public boolean replace(K k, V v, V v2) {
        int ˎ = ˎ((Object) k);
        if (ˎ >= 0) {
            V ˋ = ˋ(ˎ);
            if (ˋ == v || (v != null && v.equals(ˋ))) {
                ॱ(ˎ, v2);
                return true;
            }
        }
        return false;
    }

    public int size() {
        return this.ʽ;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        int i;
        Object ॱ;
        Object ˋ;
        Object obj2;
        if (obj instanceof dy) {
            dy dyVar = (dy) obj;
            if (size() != dyVar.size()) {
                return false;
            }
            i = 0;
            while (i < this.ʽ) {
                try {
                    ॱ = ॱ(i);
                    ˋ = ˋ(i);
                    obj2 = dyVar.get(ॱ);
                    if (ˋ == null) {
                        if (obj2 != null || !dyVar.containsKey(ॱ)) {
                            return false;
                        }
                    } else if (!ˋ.equals(obj2)) {
                        return false;
                    }
                    i++;
                } catch (NullPointerException e) {
                    return false;
                } catch (ClassCastException e2) {
                    return false;
                }
            }
            return true;
        } else if (!(obj instanceof Map)) {
            return false;
        } else {
            Map map = (Map) obj;
            if (size() != map.size()) {
                return false;
            }
            i = 0;
            while (i < this.ʽ) {
                try {
                    ॱ = ॱ(i);
                    ˋ = ˋ(i);
                    obj2 = map.get(ॱ);
                    if (ˋ == null) {
                        if (obj2 != null || !map.containsKey(ॱ)) {
                            return false;
                        }
                    } else if (!ˋ.equals(obj2)) {
                        return false;
                    }
                    i++;
                } catch (NullPointerException e3) {
                    return false;
                } catch (ClassCastException e4) {
                    return false;
                }
            }
            return true;
        }
    }

    public int hashCode() {
        int[] iArr = this.ॱॱ;
        Object[] objArr = this.ʼ;
        int i = this.ʽ;
        int i2 = 1;
        int i3 = 0;
        int i4 = 0;
        while (i3 < i) {
            Object obj = objArr[i2];
            i4 += (obj == null ? 0 : obj.hashCode()) ^ iArr[i3];
            i3++;
            i2 += 2;
        }
        return i4;
    }

    public String toString() {
        if (isEmpty()) {
            return "{}";
        }
        StringBuilder stringBuilder = new StringBuilder(this.ʽ * 28);
        stringBuilder.append('{');
        for (int i = 0; i < this.ʽ; i++) {
            if (i > 0) {
                stringBuilder.append(", ");
            }
            dy ॱ = ॱ(i);
            if (ॱ != this) {
                stringBuilder.append(ॱ);
            } else {
                stringBuilder.append("(this Map)");
            }
            stringBuilder.append('=');
            ॱ = ˋ(i);
            if (ॱ != this) {
                stringBuilder.append(ॱ);
            } else {
                stringBuilder.append("(this Map)");
            }
        }
        stringBuilder.append('}');
        return stringBuilder.toString();
    }
}
